package com.example.signsystem.service.Impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.signsystem.entity.dto.ClassScheduleDTO;
import com.example.signsystem.entity.parm.ClassScheduleParam;
import com.example.signsystem.entity.po.ClassPO;
import com.example.signsystem.mapper.ClassMapper;
import com.example.signsystem.service.IClassService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class ClassServiceImpl extends ServiceImpl<ClassMapper, ClassPO> implements IClassService {

    @Override
    public Boolean deleteBatch(List<Long> ids) {
        return this.baseMapper.deleteBatchIds(ids) > 0;
    }

    //todo 不太会模糊查询
    @Override
    public List<ClassPO> viewClassSchedule(ClassScheduleParam classScheduleParam) {
        LambdaQueryWrapper<ClassPO> lqw=null;
        /**模糊查寻**/
        if(StrUtil.isNotEmpty(classScheduleParam.getClassName())){
            lqw.like(ClassPO::getClassName,classScheduleParam.getClassName());
        }
        if(ObjectUtil.isNotEmpty(classScheduleParam.getStartTime())&&ObjectUtil.isNotEmpty(classScheduleParam.getEndTime())){
            lqw.ge(ClassPO::getStartTime,classScheduleParam.getStartTime()).le(ClassPO::getEndTime,classScheduleParam.getEndTime());
        }
        if(ObjectUtil.isNotEmpty(classScheduleParam.getWeekDay())){
            lqw.eq(ClassPO::getWeekDay,classScheduleParam.getWeekDay());
        }
        return this.baseMapper.selectList(lqw);
    }

    @Override
    public Boolean update(ClassScheduleDTO classScheduleDTO) {
        ClassPO classPO= BeanUtil.copyProperties(classScheduleDTO,ClassPO.class);
        return this.baseMapper.updateById(classPO)>0;
    }
}
